import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { DeviceVO, DeviceForm, DeviceQuery } from '@/api/device/device/types';

/**
 * 查询设备信息列表
 * @param query
 * @returns {*}
 */

export const listDevice = (query?: DeviceQuery): AxiosPromise<DeviceVO[]> => {
  return request({
    url: '/device/device/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询设备信息详细
 * @param deviceId
 */
export const getDevice = (deviceId: string | number): AxiosPromise<DeviceVO> => {
  return request({
    url: '/device/device/' + deviceId,
    method: 'get'
  });
};

/**
 * 查询设备信息详细
 * @param deviceId
 */
export const queryByPositionId = (positionid: string | number): AxiosPromise<DeviceVO[]> => {
  return request({
    url: '/device/device/queryByPositionId/' + positionid,
    method: 'get'
  });
};

/**
 * 新增设备信息
 * @param data
 */
export const addDevice = (data: DeviceForm) => {
  return request({
    url: '/device/device',
    method: 'post',
    data: data
  });
};

/**
 * 修改设备信息
 * @param data
 */
export const updateDevice = (data: DeviceForm) => {
  return request({
    url: '/device/device',
    method: 'put',
    data: data
  });
};

/**
 * 删除设备信息
 * @param deviceId
 */
export const delDevice = (deviceId: string | number | Array<string | number>) => {
  return request({
    url: '/device/device/' + deviceId,
    method: 'delete'
  });
};

/**
 * 格子开锁
 * @param deviceGridId
 */
export const operDommand = (deviceNo: string,operType: string) => {
  return request({
    url: '/device/device/operDommand',
    method: 'post',
    data:{'deviceNo':deviceNo,'operType':operType}
  });
};

// export const importGrid = (formData: any) => {
//   return request({
//     url: '/device/device/importGrid',
//     method: 'post',
//     data:formData
//   });
// };

export const importGrid = (file: any,deviceNo: string) => {
  return request({
    url: '/device/device/importGrid',
    method: 'post',
    data: {"file":file.file,"deviceNo":deviceNo},
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
};
